<template>
    <view class="pages">
        <view class="list-item" v-for="item in sortList" :key="item.id" @click="selectSort(item)">
            <view class="list-item-left">
                <text>{{item.classify_name}}</text>
            </view>
            <view class="list-item-right">
                <img src="/static/img/right.png" />
            </view>
        </view>
    </view>
</template>

<script>
    export default {
        name: "selectSort",
        data(){
            return{
                circle_id: '',
                sortList: []
            }
        },
        onLoad(query){
            this.circle_id = query.circle_id
        },
        onShow(){
          this.getEnableArticleClassify();
        },
        methods:{
            //获取圈子帖子分类
            async getEnableArticleClassify(){
                let params = {
                    circle_id: this.circle_id,
                    user_token: uni.getStorageSync('userToken'),
                }
                const res = await this.$api.getEnableArticleClassify(params);
                if (res.data.level == 'success'){
                    // console.log(res)
                    this.sortList = res.data.data;
                    if (res.data.data.length==0){
                        uni.showToast({
                            icon:'none',
                            title:'该圈子暂时没有分类~'
                        })
                    }
                }else {
                    uni.showToast({
                        icon:'none',
                        title:res.data.message
                    })
                }
            },
            //选中分类
            selectSort(item){
                let pages = getCurrentPages();
                let prevPage = pages[pages.length - 2];
                prevPage.setData({
                    postSorts:{
                        name : item.classify_name,
                        id : item.classify_id
                    }
                })
                uni.navigateBack({
                    delta: 1
                })
            }
        }
    }
</script>

<style scoped lang="scss">
    .pages{
        padding: 3vw;
        display: flex;
        flex-direction: column;
        .list-item{
            display: flex;
            flex-direction: row;
            justify-content: left;
            padding: 30rpx 0;
            border-bottom: 1rpx solid #E6E6E6;
            .list-item-left{
                width: 75vw;
                display: flex;
                align-items: center;
                padding: 0 2vw;
                text{
                    font-size: 36rpx;
                }
            }
            .list-item-right{
                width: 7vw;
                height: 7vw;
                padding: 4vw;
            }
        }
    }
</style>